/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Estacionamento.DAOEspecifico;

import Estacionamento.ClassesBasicas.Cliente;
import Estacionamento.DAOGenerico.DAOGenerico;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;
import javax.persistence.TypedQuery;

/**
 *
 * @author italo.valenca
 */
public class DAOCliente extends DAOGenerico<Cliente> implements IDAOCliente {

    
    /*
     EntityManagerFactory emf;
     EntityManager em;

     public DAOCliente() {
     emf = Persistence.createEntityManagerFactory("estacionamento");
     em = emf.createEntityManager();
     }
     @Override
     public void ExcluirCliente(Cliente cli) throws Exception {
     try {

     em.getTransaction().begin();
     em.remove(cli);
     //em.flush();
     //em.remove(em.getReference(Cliente.class, cli.getId()));
     em.getTransaction().commit();
     emf.close();
     } catch (Exception ex) {
     throw new Exception(ex.getMessage());
     }
     }

     @Override
     public Cliente ListarCliente(String cpf) throws Exception {
     Cliente cli = new Cliente();
     cli = null;
     try {
     Query consulta = em.createQuery("select cliente from Cliente cliente");
     List<Cliente> listCliente = consulta.getResultList();
     int i;
     for (i = 0; i < listCliente.size(); i++) {
     if (listCliente.get(i).getCpf().trim().equals(cpf)) {
     cli = listCliente.get(i);
     }
     }
     //em.getTransaction().commit();
     emf.close();
     return cli;

     } catch (Exception ex) {
     throw new Exception(ex.getMessage());
     }
     }
     /*
     @Override
     public List<Cliente> ListarClientesPorNome(Cliente cli) throws Exception {

     try {
     em.getTransaction().begin();
     Query consulta = em.createQuery("select cliente from Cliente cliente where cliente.nome = '" + cli.getNome() + "'");
     List<Cliente> cliente = consulta.getResultList();
     em.getTransaction().commit();
     emf.close();
     return cliente;

     } catch (Exception ex) {
     throw new Exception(ex.getMessage());
     }
     }
    
     @Override
     public void AlterarLoginSenha(Cliente cli) throws Exception {
     try {
     em.getTransaction().begin();
     Query query = em.createQuery("UPDATE Cliente set login = :login, senha = :senha  WHERE cpf = :cpf");
     //query.setParameter("login", cli.getLogin());
     query.setParameter("cpf", cli.getCpf());
     //query.setParameter("senha", cli.getSenha());
     query.executeUpdate();
     em.getTransaction().commit();
     emf.close();
     } catch (Exception ex) {
     throw new Exception(ex.getMessage());
     }
     }

     @Override
     public List<Cliente> VerificarLogin(Cliente cli) throws Exception {
     try {
     em.getTransaction().begin();
     Query consulta = em.createQuery("select cli from Cliente cli WHERE cli.login = :login and cli.senha = :senha");
     consulta.setParameter("login", cli.getLogin());
     consulta.setParameter("senha", cli.getSenha());
     List<Cliente> clientes = consulta.getResultList();
     em.getTransaction().commit();
     emf.close();
     return clientes;

     } catch (Exception ex) {
     throw new Exception(ex.getMessage());
     }
     }*/
}
